﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsTools
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {

                List<object> listStr = new List<object>();

                //using (SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=himall2a;Integrated Security=True"))
                //"Data Source=.;Initial Catalog=docbm;Integrated Security=True"//

                var builder = new SqlConnectionStringBuilder();
                builder["Data Source"] = ".";
                builder["integrated Security"] = true;
                builder["Initial Catalog"] = "docbm1";
                builder.ColumnEncryptionSetting = SqlConnectionColumnEncryptionSetting.Enabled;
                var dt = new DataTable();
                using (SqlConnection conn = new SqlConnection(builder.ToString()))
                {
                    //conn.Open();
                    using (SqlCommand com = new SqlCommand())
                    {
                        //com.Connection = conn;
                        //com.CommandType = CommandType.Text;
                        //com.CommandText = "select * from hyclub";

                        SqlDataAdapter da = new SqlDataAdapter("select * from hyclub", conn);                      
                        conn.Open();
                        da.Fill(dt);
                        conn.Close();
                        dataGridView1.DataSource = dt;
                    }
                }

               

            }
            catch (Exception ex)
            {

                txtmsg.Text = ex.Message;
                txtInfo.Text = ex.StackTrace;
            }


        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

            try
            {

                List<object> listStr = new List<object>();
                var builder = new SqlConnectionStringBuilder();
                builder["Data Source"] = ".";
                builder["integrated Security"] = true;
                builder["Initial Catalog"] = "docbm1";
                builder.ColumnEncryptionSetting = SqlConnectionColumnEncryptionSetting.Enabled;

                using (SqlConnection conn = new SqlConnection(builder.ToString()))
                {
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.Connection = conn;
                        cmd.CommandType = CommandType.Text;                 

                        cmd.CommandText = @"INSERT INTO [dbo].[HyClub]  ([ID],[HyNumber],[HyName])  VALUES (@ID,@HyNumber,@HyName);";
 
                         SqlParameter paramSSN = cmd.CreateParameter();
                         paramSSN.ParameterName = "@ID";
                         paramSSN.Direction = ParameterDirection.Input;
                         paramSSN.Value = textBox1.Text.ToString();                    
                         cmd.Parameters.Add(paramSSN);


                         SqlParameter paramSSN1 = cmd.CreateParameter();
                         paramSSN1.ParameterName = @"@HyNumber";
                         paramSSN1.Direction = ParameterDirection.Input;
                         paramSSN1.Value = textBox3.Text.ToString();
                        
                         cmd.Parameters.Add(paramSSN1);


                         SqlParameter paramSSN2 = cmd.CreateParameter();
                         paramSSN2.ParameterName = @"@HyName";
                         paramSSN2.Direction = ParameterDirection.Input;
                         paramSSN2.Value = textBox2.Text.ToString();                        
                         cmd.Parameters.Add(paramSSN2);

                         cmd.ExecuteNonQuery();
                                
                    }
                }

                var a = listStr;

            }
            catch (Exception ex)
            {

                txtmsg.Text = ex.Message;
                txtInfo.Text = ex.StackTrace;
            }







        }


    }
}
